package com.wingsfrog.puzzle.modules.dao;

import com.wingsfrog.puzzle.modules.entity.User;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;

public interface UserDao extends CrudRepository<User,Integer>{
    @Query("select u " +
            "from User u " +
            "where u.openId=?1")
    public User findByOpenId(String openId);

    @Query("select count(u.id) " +
            "from User u " +
            "where u.openId=?1")
    public int existByOpenId(String openId);

    @Modifying
    @Query("update User set coins=?2 where id=?1")
    public void updateCoins(int id, Integer coins);
}
